/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import source.DatabaseHandler;

/**
 *
 * @author padsilva
 */
public class UtilizadorMenuMinhasSalas extends javax.swing.JFrame {
    DatabaseHandler connect;
    int id;
    String username;
    /**
     * Creates new form UtilizadorMenuMinhasSalas
     */
    public UtilizadorMenuMinhasSalas(DatabaseHandler conn,String usernameR,int idR) {
        connect=conn;
        username=usernameR;
        id=idR;
        initComponents();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation((screenSize.width - this.getWidth()) / 2, (screenSize.height - this.getHeight()) / 2);
        String salas=connect.searchMyChatroom(usernameR);
        
        int aux=0;
        String sala="";
        DefaultListModel listModel = new DefaultListModel();
        StringTokenizer st = new StringTokenizer(salas, "/");
        while (st.hasMoreTokens()) {
            StringTokenizer st1 =new StringTokenizer(st.nextToken(),"#");
            
            while(st1.hasMoreTokens()){
                if(aux==0){
                    sala+="Nome: ";
                    sala+=st1.nextToken().toString()+"\n ";
                }
                else if(aux==1){
                    sala+="Tema: ";
                    sala+=st1.nextToken().toString()+"\n ";
                }
                else if(aux==2){
                    if(st1.nextToken().equals("1")){
                        sala+="[Publico]";
                    }
                    else sala+="[Privado]";
                }
                
                aux++;
            }
            listModel.addElement(sala);
            sala="";
            aux=0;
        }
        listaMinhasSalas.setModel(listModel);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonVoltar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listaMinhasSalas = new javax.swing.JList();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        criarNomeSala = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        criarTemaSala = new javax.swing.JTextField();
        buttonAdicionaSala = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        modificarNomeSala = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        modificarTemaSala = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        botaoGerirSala = new javax.swing.JButton();
        buttonFecharSala = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        barraMenus = new javax.swing.JMenuBar();
        menuPrincipal = new javax.swing.JMenu();
        botaoUtilizadorMenuPrincipal = new javax.swing.JMenuItem();
        menuMensagensPrivadas = new javax.swing.JMenu();
        botaoUtilizadorMenuMensagensPrivadas = new javax.swing.JMenuItem();
        botaoUtilizadorMensagensEnviadas = new javax.swing.JMenuItem();
        botaoUtilizadorMensagensRecebidas = new javax.swing.JMenuItem();
        botaoMenuMensagensNovas = new javax.swing.JMenuItem();
        menuPerfil = new javax.swing.JMenu();
        botaoParaUtilizadorMenuEditarPerfil = new javax.swing.JMenuItem();
        botaoRemoveSai = new javax.swing.JMenuItem();
        menuProcurar = new javax.swing.JMenu();
        botaoMenuProcurarUtilizador = new javax.swing.JMenuItem();
        menuSalas = new javax.swing.JMenu();
        botaoMinhasSalas = new javax.swing.JMenuItem();
        botaoPesquisarSalas = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        buttonVoltar.setText("Voltar");
        buttonVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonVoltarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Minhas Salas"));

        jScrollPane1.setViewportView(listaMinhasSalas);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Criar Nova Sala"));

        jLabel1.setText("Nome:");

        jLabel2.setText("Tema:");

        buttonAdicionaSala.setText("OK");
        buttonAdicionaSala.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAdicionaSalaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(criarNomeSala))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(criarTemaSala)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(buttonAdicionaSala))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(criarNomeSala, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(criarTemaSala, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(buttonAdicionaSala))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Modificar Sala"));

        jLabel3.setText("Nome:");

        jLabel4.setText("Tema:");

        jButton2.setText("OK");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(modificarNomeSala))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(modificarTemaSala)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jButton2))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(modificarNomeSala, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(modificarTemaSala, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton2))
        );

        botaoGerirSala.setText("Gerir Sala");
        botaoGerirSala.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoGerirSalaActionPerformed(evt);
            }
        });

        buttonFecharSala.setText("Fechar Sala");
        buttonFecharSala.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonFecharSalaActionPerformed(evt);
            }
        });

        jButton4.setText("Listar Mensagens");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        menuPrincipal.setText("Menu Principal");

        botaoUtilizadorMenuPrincipal.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
        botaoUtilizadorMenuPrincipal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/home-icon.png"))); // NOI18N
        botaoUtilizadorMenuPrincipal.setText("Home");
        botaoUtilizadorMenuPrincipal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoUtilizadorMenuPrincipalActionPerformed(evt);
            }
        });
        menuPrincipal.add(botaoUtilizadorMenuPrincipal);

        barraMenus.add(menuPrincipal);

        menuMensagensPrivadas.setText("Mensagens Privadas");

        botaoUtilizadorMenuMensagensPrivadas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        botaoUtilizadorMenuMensagensPrivadas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon mensagem nova.png"))); // NOI18N
        botaoUtilizadorMenuMensagensPrivadas.setText("Criar");
        botaoUtilizadorMenuMensagensPrivadas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoUtilizadorMenuMensagensPrivadasActionPerformed(evt);
            }
        });
        menuMensagensPrivadas.add(botaoUtilizadorMenuMensagensPrivadas);

        botaoUtilizadorMensagensEnviadas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        botaoUtilizadorMensagensEnviadas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon mensagem enviadas.png"))); // NOI18N
        botaoUtilizadorMensagensEnviadas.setText("Enviadas");
        botaoUtilizadorMensagensEnviadas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoUtilizadorMensagensEnviadasActionPerformed(evt);
            }
        });
        menuMensagensPrivadas.add(botaoUtilizadorMensagensEnviadas);

        botaoUtilizadorMensagensRecebidas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        botaoUtilizadorMensagensRecebidas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon mensagens recebidas.png"))); // NOI18N
        botaoUtilizadorMensagensRecebidas.setText("Recebidas");
        botaoUtilizadorMensagensRecebidas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoUtilizadorMensagensRecebidasActionPerformed(evt);
            }
        });
        menuMensagensPrivadas.add(botaoUtilizadorMensagensRecebidas);

        botaoMenuMensagensNovas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        botaoMenuMensagensNovas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/1355506850_label_new blue.png"))); // NOI18N
        botaoMenuMensagensNovas.setText("Novas Mensagens");
        botaoMenuMensagensNovas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoMenuMensagensNovasActionPerformed(evt);
            }
        });
        menuMensagensPrivadas.add(botaoMenuMensagensNovas);

        barraMenus.add(menuMensagensPrivadas);

        menuPerfil.setText("Perfil");

        botaoParaUtilizadorMenuEditarPerfil.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        botaoParaUtilizadorMenuEditarPerfil.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon editar perfil.png"))); // NOI18N
        botaoParaUtilizadorMenuEditarPerfil.setText("Editar");
        botaoParaUtilizadorMenuEditarPerfil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoParaUtilizadorMenuEditarPerfilActionPerformed(evt);
            }
        });
        menuPerfil.add(botaoParaUtilizadorMenuEditarPerfil);

        botaoRemoveSai.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        botaoRemoveSai.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon remover utilizador.png"))); // NOI18N
        botaoRemoveSai.setText("Remover");
        botaoRemoveSai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoRemoveSaiActionPerformed(evt);
            }
        });
        menuPerfil.add(botaoRemoveSai);

        barraMenus.add(menuPerfil);

        menuProcurar.setText("Procurar Utilizadores");

        botaoMenuProcurarUtilizador.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        botaoMenuProcurarUtilizador.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon procurar utilizador.png"))); // NOI18N
        botaoMenuProcurarUtilizador.setText("Procurar");
        botaoMenuProcurarUtilizador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoMenuProcurarUtilizadorActionPerformed(evt);
            }
        });
        menuProcurar.add(botaoMenuProcurarUtilizador);

        barraMenus.add(menuProcurar);

        menuSalas.setText("Salas");

        botaoMinhasSalas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
        botaoMinhasSalas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon minhas salas.png"))); // NOI18N
        botaoMinhasSalas.setText("Minhas Salas");
        botaoMinhasSalas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoMinhasSalasActionPerformed(evt);
            }
        });
        menuSalas.add(botaoMinhasSalas);

        botaoPesquisarSalas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        botaoPesquisarSalas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon procurar sala.png"))); // NOI18N
        botaoPesquisarSalas.setText("Pesquisar");
        botaoPesquisarSalas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoPesquisarSalasActionPerformed(evt);
            }
        });
        menuSalas.add(botaoPesquisarSalas);

        barraMenus.add(menuSalas);

        setJMenuBar(barraMenus);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(16, 16, 16)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(buttonVoltar))
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(buttonFecharSala, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoGerirSala)
                        .addGap(215, 215, 215)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton4)
                        .addGap(5, 5, 5)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(buttonVoltar)
                            .addComponent(buttonFecharSala, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(botaoGerirSala, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonVoltarActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMenuPrincipal menu = new UtilizadorMenuPrincipal(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_buttonVoltarActionPerformed

    private void botaoGerirSalaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoGerirSalaActionPerformed
        // TODO add your handling code here:
        String nomeSala="";
        String selected = listaMinhasSalas.getSelectedValue().toString();
        Matcher matcher = Pattern.compile("(?<=Nome: ).*").matcher(selected);
        matcher.find();
        nomeSala=matcher.group();
        
        String chatroomInformation=connect.getChatroom(nomeSala);
        StringTokenizer st=new StringTokenizer(chatroomInformation,"#");
        
        String idSala=st.nextToken();
        this.setVisible(false);
        UtilizadorGerirSalaPopup menu = new UtilizadorGerirSalaPopup(connect, username, id,Integer.parseInt(idSala));
        menu.setVisible(true);
    }//GEN-LAST:event_botaoGerirSalaActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        String nomeSala="";
        String selected = listaMinhasSalas.getSelectedValue().toString();
        Matcher matcher = Pattern.compile("(?<=Nome: ).*").matcher(selected);
        matcher.find();
        nomeSala=matcher.group();
        
        String chatroomInformation=connect.getChatroom(nomeSala);
        StringTokenizer st=new StringTokenizer(chatroomInformation,"#");
        
        String idSala=st.nextToken();
        UtilizadorMensagensSala menu= new UtilizadorMensagensSala(connect, username, id,Integer.parseInt(idSala));
        menu.setVisible(true);
        
        
        
    }//GEN-LAST:event_jButton4ActionPerformed

    private void buttonAdicionaSalaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAdicionaSalaActionPerformed
        // TODO add your handling code here:
        String nomeSala= criarNomeSala.getText();
        String tipoSala= criarTemaSala.getText();
        
        if(connect.addChatroom(nomeSala, username, tipoSala).equals("true"))JOptionPane.showMessageDialog(this, "A sua sala foi criada com sucesso!", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
        else JOptionPane.showMessageDialog(this, "Não foi possível criar a sua sala, tente de novo!", "Erro", JOptionPane.ERROR_MESSAGE);
    }//GEN-LAST:event_buttonAdicionaSalaActionPerformed

    private void botaoUtilizadorMenuPrincipalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoUtilizadorMenuPrincipalActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMenuPrincipal menu = new UtilizadorMenuPrincipal(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoUtilizadorMenuPrincipalActionPerformed

    private void botaoUtilizadorMenuMensagensPrivadasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoUtilizadorMenuMensagensPrivadasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMenuMensagensPrivadas menu = new UtilizadorMenuMensagensPrivadas(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoUtilizadorMenuMensagensPrivadasActionPerformed

    private void botaoUtilizadorMensagensEnviadasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoUtilizadorMensagensEnviadasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMensagensEnviadas menu = new UtilizadorMensagensEnviadas(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoUtilizadorMensagensEnviadasActionPerformed

    private void botaoUtilizadorMensagensRecebidasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoUtilizadorMensagensRecebidasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMensagensRecebidas menu = new UtilizadorMensagensRecebidas(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoUtilizadorMensagensRecebidasActionPerformed

    private void botaoMenuMensagensNovasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoMenuMensagensNovasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMensagensRecebidasNovas menu = new UtilizadorMensagensRecebidasNovas(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoMenuMensagensNovasActionPerformed

    private void botaoParaUtilizadorMenuEditarPerfilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoParaUtilizadorMenuEditarPerfilActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMenuEditarPerfil menu = new UtilizadorMenuEditarPerfil(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoParaUtilizadorMenuEditarPerfilActionPerformed

    private void botaoRemoveSaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoRemoveSaiActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        removerUtilizador menu = new removerUtilizador(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoRemoveSaiActionPerformed

    private void botaoMenuProcurarUtilizadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoMenuProcurarUtilizadorActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        procurarUtilizadores menu = new procurarUtilizadores(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoMenuProcurarUtilizadorActionPerformed

    private void botaoMinhasSalasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoMinhasSalasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMenuMinhasSalas menu = new UtilizadorMenuMinhasSalas(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoMinhasSalasActionPerformed

    private void botaoPesquisarSalasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoPesquisarSalasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMenuPesquisarSalas menu = new UtilizadorMenuPesquisarSalas(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoPesquisarSalasActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        
        String nomeSala="";
        String selected = listaMinhasSalas.getSelectedValue().toString();
        Matcher matcher = Pattern.compile("(?<=Nome: ).*").matcher(selected);
        matcher.find();
        nomeSala=matcher.group();
        
        String chatroomInformation=connect.getChatroom(nomeSala);
        StringTokenizer st=new StringTokenizer(chatroomInformation,"#");
        
        String id=st.nextToken();
        String nome=st.nextToken();
        String nomeCriador=st.nextToken();
        String tipoSala=st.nextToken();
     
        String novoNome=modificarNomeSala.getText();
        String novoTema=modificarTemaSala.getText();
        if(!novoNome.equals("")){
            if(!novoTema.equals("")){
                
                if(connect.updateChatroom(Integer.parseInt(id), novoNome,novoTema))JOptionPane.showMessageDialog(this, "A sua sala foi modificada com sucesso!", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
            }
            else{
                if(connect.updateChatroom(Integer.parseInt(id), novoNome,tipoSala))JOptionPane.showMessageDialog(this, "A sua sala foi modificada com sucesso!", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        else{
            if(!novoTema.equals("")){

                if(connect.updateChatroom(Integer.parseInt(id), nome,novoTema))JOptionPane.showMessageDialog(this, "A sua sala foi modificada com sucesso!", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        
            
        
        
        
    }//GEN-LAST:event_jButton2ActionPerformed

    private void buttonFecharSalaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFecharSalaActionPerformed
        // TODO add your handling code here:
        String nomeSala="";
        String selected = listaMinhasSalas.getSelectedValue().toString();
        Matcher matcher = Pattern.compile("(?<=Nome: ).*").matcher(selected);
        matcher.find();
        nomeSala=matcher.group();
        
        String chatroomInformation=connect.getChatroom(nomeSala);
        StringTokenizer st=new StringTokenizer(chatroomInformation,"#");
        
        String id=st.nextToken();
        
        if(connect.setInvisibleChatroom(Integer.parseInt(id)))JOptionPane.showMessageDialog(this, "A sua sala está agora invisivel e não será vista pelos outros utilizadores!", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
        else JOptionPane.showMessageDialog(this, "Não foi possivel concluir a operação, tente de novo mais tarde!", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_buttonFecharSalaActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar barraMenus;
    private javax.swing.JButton botaoGerirSala;
    private javax.swing.JMenuItem botaoMenuMensagensNovas;
    private javax.swing.JMenuItem botaoMenuProcurarUtilizador;
    private javax.swing.JMenuItem botaoMinhasSalas;
    private javax.swing.JMenuItem botaoParaUtilizadorMenuEditarPerfil;
    private javax.swing.JMenuItem botaoPesquisarSalas;
    private javax.swing.JMenuItem botaoRemoveSai;
    private javax.swing.JMenuItem botaoUtilizadorMensagensEnviadas;
    private javax.swing.JMenuItem botaoUtilizadorMensagensRecebidas;
    private javax.swing.JMenuItem botaoUtilizadorMenuMensagensPrivadas;
    private javax.swing.JMenuItem botaoUtilizadorMenuPrincipal;
    private javax.swing.JButton buttonAdicionaSala;
    private javax.swing.JButton buttonFecharSala;
    private javax.swing.JButton buttonVoltar;
    private javax.swing.JTextField criarNomeSala;
    private javax.swing.JTextField criarTemaSala;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList listaMinhasSalas;
    private javax.swing.JMenu menuMensagensPrivadas;
    private javax.swing.JMenu menuPerfil;
    private javax.swing.JMenu menuPrincipal;
    private javax.swing.JMenu menuProcurar;
    private javax.swing.JMenu menuSalas;
    private javax.swing.JTextField modificarNomeSala;
    private javax.swing.JTextField modificarTemaSala;
    // End of variables declaration//GEN-END:variables
}
